import java.util.Scanner;
public class Ex3 {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);  
		int firstLargest = 0;			
		int secondLargest = 0;
		int thirdLargest = 0;
		int forthLargest = 0;
		int userInput = -1;
		
		while (userInput != 0){						//Loop checks where the inputed number stands in relation 
													//to previously inserted numbers and updated the registers accordingly 
			
			userInput = sc.nextInt(); 				//Getting input from user.
			
			if(userInput > firstLargest){
				firstLargest = userInput;
			
			}else if (userInput > secondLargest){
				secondLargest = userInput;
			
			}else if (userInput > thirdLargest){
				thirdLargest = userInput;
			
			}else if (userInput > forthLargest){
				forthLargest = userInput;
			}
		}
		sc.close();
		
		System.out.println(forthLargest);
		
		
		
		
	}


}
